package com.fu.consumer.controller;

import com.fu.core.common.JsonResult;
import com.fu.core.pojo.OrderSku;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author 付龙江
 * @date 2022/1/29 16:30
 */
@RestController
@RequestMapping("/cart")
@CrossOrigin
@Api(tags = "前台购物车相关接口")
public class CartController {

    @PostMapping("/cartList")
    @ApiOperation(value = "购物车列表")
    public Map<String,Object> cartList(){
        List<OrderSku> orderSkuList = new ArrayList<>();
        for (int i = 1; i < 4; i++) {
           OrderSku orderSku = new OrderSku(i,"/还没有图片","新疆大西瓜","1个装",38.00,2,76.00,null);
           orderSkuList.add(orderSku);
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("cartList",orderSkuList);
        return jsonResult.getMap();
    }


    @PostMapping("/changeNum")
    @ApiOperation(value = "加减数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "购物车中商品编号", dataType = "Integer", required = true),
            @ApiImplicitParam(name = "num", value = "修改后的数量", dataType = "Integer", required = true)
    })
    public Map<String,Object> changeNum(Integer id, Integer num){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setField("num",num);
        return jsonResult.getMap();
    }

    @PostMapping("/deleteCartGoods")
    @ApiOperation(value = "把商品从购物车中删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "购物车中商品编号", dataType = "Integer", required = true)
    })
    public Map<String,Object> deleteCartGoods(Integer id){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("code",200);
        jsonResult.setMsg("删除成功");
        return jsonResult.getMap();
    }

}
